package mymobile.diagram.providers;

import mymobile.diagram.edit.parts.AppMobileAppNameEditPart;
import mymobile.diagram.edit.parts.ImageNameEditPart;
import mymobile.diagram.edit.parts.InputNameEditPart;
import mymobile.diagram.edit.parts.LabelNameEditPart;
import mymobile.diagram.edit.parts.ListNameEditPart;
import mymobile.diagram.edit.parts.SettingSettingNameEditPart;
import mymobile.diagram.edit.parts.ViewViewNameEditPart;
import mymobile.diagram.parsers.MessageFormatParser;
import mymobile.diagram.part.MyMobileVisualIDRegistry;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class MyMobileParserProvider extends AbstractProvider implements
		IParserProvider {

	/**
	 * @generated
	 */
	private IParser viewViewName_5005Parser;

	/**
	 * @generated
	 */
	private IParser getViewViewName_5005Parser() {
		if (viewViewName_5005Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getView_ViewName() };
			MessageFormatParser parser = new MessageFormatParser(features);
			viewViewName_5005Parser = parser;
		}
		return viewViewName_5005Parser;
	}

	/**
	 * @generated
	 */
	private IParser inputName_5006Parser;

	/**
	 * @generated
	 */
	private IParser getInputName_5006Parser() {
		if (inputName_5006Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getComponent_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			inputName_5006Parser = parser;
		}
		return inputName_5006Parser;
	}

	/**
	 * @generated
	 */
	private IParser listName_5007Parser;

	/**
	 * @generated
	 */
	private IParser getListName_5007Parser() {
		if (listName_5007Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getComponent_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			listName_5007Parser = parser;
		}
		return listName_5007Parser;
	}

	/**
	 * @generated
	 */
	private IParser appMobileAppName_5008Parser;

	/**
	 * @generated
	 */
	private IParser getAppMobileAppName_5008Parser() {
		if (appMobileAppName_5008Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getAppMobile_AppName() };
			MessageFormatParser parser = new MessageFormatParser(features);
			appMobileAppName_5008Parser = parser;
		}
		return appMobileAppName_5008Parser;
	}

	/**
	 * @generated
	 */
	private IParser labelName_5009Parser;

	/**
	 * @generated
	 */
	private IParser getLabelName_5009Parser() {
		if (labelName_5009Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getComponent_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			labelName_5009Parser = parser;
		}
		return labelName_5009Parser;
	}

	/**
	 * @generated
	 */
	private IParser settingSettingName_5010Parser;

	/**
	 * @generated
	 */
	private IParser getSettingSettingName_5010Parser() {
		if (settingSettingName_5010Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getSetting_SettingName() };
			MessageFormatParser parser = new MessageFormatParser(features);
			settingSettingName_5010Parser = parser;
		}
		return settingSettingName_5010Parser;
	}

	/**
	 * @generated
	 */
	private IParser imageName_5011Parser;

	/**
	 * @generated
	 */
	private IParser getImageName_5011Parser() {
		if (imageName_5011Parser == null) {
			EAttribute[] features = new EAttribute[] { mymobile.mobileTest.MobileTestPackage.eINSTANCE
					.getComponent_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			imageName_5011Parser = parser;
		}
		return imageName_5011Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case ViewViewNameEditPart.VISUAL_ID:
			return getViewViewName_5005Parser();
		case InputNameEditPart.VISUAL_ID:
			return getInputName_5006Parser();
		case ListNameEditPart.VISUAL_ID:
			return getListName_5007Parser();
		case AppMobileAppNameEditPart.VISUAL_ID:
			return getAppMobileAppName_5008Parser();
		case LabelNameEditPart.VISUAL_ID:
			return getLabelName_5009Parser();
		case SettingSettingNameEditPart.VISUAL_ID:
			return getSettingSettingName_5010Parser();
		case ImageNameEditPart.VISUAL_ID:
			return getImageName_5011Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(MyMobileVisualIDRegistry.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(MyMobileVisualIDRegistry.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (MyMobileElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
